package com.xiaoye.qbproject.controller.base;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.sql.DataSource;
import java.sql.Connection;

/**
 * @author : ChenYao
 * @version : 1.0
 * @description :
 * @create : 2024-12-25 16:54
 */
@RestController
public class TestController {
    @Autowired
    private DataSource dataSource;

    @GetMapping("/test")
    public String testConnection() {
        try (Connection connection = dataSource.getConnection()) {
            return "Database connection successful!";
        } catch (Exception e) {
            return "Database connection failed: " + e.getMessage();
        }
    }
}